package com.xl.rentkeeper.business;

import com.xl.fuse.protos.app.UpgradeInfo;
import com.xl.fuse.protos.packet.Packet;
import com.xl.rentkeeper.log.QLog;
import com.xl.rentkeeper.mgr.UiObserverManager;
import com.xl.rentkeeper.net.Request;

/**
 * Created by Administrator on 2015/9/2.
 * 更新的logic
 */
public class UpdateLogic extends BaseLogic {
    private UpgradeInfo upgradeInfo;

    public static UpdateLogic getInstance() {
        return (UpdateLogic) SingletonRegistry.getInstance(UpdateLogic.class);
    }

    //查询更新
    public void checkUpdate() {
        sendReq(UserLogic.getInstance().getUid(), CMD_CHECK_UPDATE, null, null);
    }


    public void onCheckUpdateResp(Request req, Packet resp){
        if (resp.ret == 0) {
            upgradeInfo = getResp(resp,UpgradeInfo.class);
            QLog.d(this, "resp " + upgradeInfo);
        }
        UiObserverManager.getInstance().dispatchEvent(req.packet.cmd, resp.ret == 0, resp.error, null);
    }

    public UpgradeInfo getUpgradeInfo(){
        return upgradeInfo;
    }

    @Override
    public void onResp(Request req, Packet resp) {
        super.onResp(req, resp);
        Packet packet = req.packet;
        String cmd = packet.cmd;
        if (cmd.equals(CMD_CHECK_UPDATE)){
            onCheckUpdateResp(req,resp);
        }
    }
}
